import java.util.Random;
import java.util.Scanner;

public class TestDemo {
    //数九问题
    public static void main6(String[] args) {
        int count = 0;//计数器
        for(int i = 0;i < 101;i++){
            if(i % 10 == 9){
                count++;
            }
            if(i / 10 == 9){
                count ++;
            }
        }
        System.out.println("共有"+count+"个9");
    }
    //加减交替和
    public static void main5(String[] args) {
        double sum = 0;
        int flag = 1;//控制符号
        for(int i = 1;i < 100;i++){
            sum += 1.0 * flag / i;
            flag *= -1;
        }
        System.out.println("加减交替和为"+sum);
    }
    //求最大公约数
    public static void main4(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n1 = scanner.nextInt();
        int n2 = scanner.nextInt();
        int n3 = n1 % n2;
        while(n3 != 0){//辗转相除法
            n1 = n2;
            n2 = n3;
            n3 = n1 % n2;
        }
        System.out.println("最大公约数为"+n2);
    }
    //乘法口诀表
    public static void main3(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int line = scanner.nextInt();
        for(int i = 1;i <= line;i++){
            for(int j = 1;j <= i;j++){
                System.out.print(j+"*"+i+"="+j*i+"\t");
            }
            System.out.println();
        }
    }
    //判断素数
    public static void main2(String[] args) {
        System.out.println("请输入一个数:>");
        Scanner scanner = new Scanner(System.in);
        int num = scanner.nextInt();
        int i = 2;
        for(;i <= Math.sqrt(num);i++){//开平方判断，省时省力
            if((num % i) == 0){
                System.out.println("输入数不是素数!");
                break;
            }
        }
        if(i > Math.sqrt(num)){
            System.out.println("输入数是素数!");
        }
    }
    //猜数字游戏
    public static void menu(){
        System.out.println("**************");
        System.out.println("**  1.Play  **");
        System.out.println("**  0.Exit  **");
        System.out.println("**************");
    }
    public static void game(){
        Random random = new Random();//随机数声明
        int toGuess = random.nextInt(100);//生成0~99的随机数
        int count = 0;//计数器
        Scanner scanner = new Scanner(System.in);
        while(true){
            System.out.println("请输入你想猜的数字:>");
            int num = scanner.nextInt();//读取整数
            if(num < toGuess){
                System.out.println("猜小了！");
                count++;
            } else if (num > toGuess) {
                System.out.println("猜大了!");
                count++;
            }else {
                System.out.println("恭喜你！猜到了！");
                System.out.println("目标数为"+toGuess);
                count++;
                System.out.println("你共计猜了"+count+"次");
                break;//跳出循环
            }
        }
        if(count <= 5){
            System.out.println("登峰造极！");
        } else if (count < 10) {
            System.out.println("十分优秀！");
        }else {
            System.out.println("还需努力！");
        }
    }
    public static void main(String[] args) {
        boolean flag = true;//判断器
        Scanner scanner = new Scanner(System.in);//输入声明
        while(flag){
            menu();//菜单函数
            System.out.println("请输入你的选择:>");
            int input = scanner.nextInt();
            switch(input) {
                case 1:
                    game();
                    break;
                case 0:
                    System.out.println("退出游戏!");
                    flag = false;
                    break;
                default:
                    System.out.println("选择错误请重新选择!");
                    break;
            }
        }
        scanner.close();//关闭Scanner这个类
    }
}
